layui.use(['form','table'], function() {
	var form = layui.form;
	var table = layui.table;

	/*加载学校类型下拉框*/
	$.ajax({
		type : 'get',
		url : '../json/schoolType.json',
		datatype : 'json',
		success : function(schooltypedate) {
			if (schooltypedate.code == 0) {
				var str = "";
				for(var i = 0; i < schooltypedate.count; i++){
					str += '<option value=' + schooltypedate.data[i].id + '>'+ schooltypedate.data[i].name+'</option>';
				}
				$("#selschooltype").append(str);
				form.render("select");
			}
		}
	});
	
	/*点击学校类型下拉框*/
	form.on('select(selschooltype)', function(data) {
		var schooltype = data.value;
		if(schooltype=="00" || schooltype==null || schooltype=='null'){
			schooltype="";
		}
		$("#selschool").html("");
		//根据阶段筛选学校
		$.ajax({
			type : 'get',
			url : '../sysschoolmanagement/getschoolbywhere?schooltype='+schooltype,
			datatype : 'json',
			success : function(schooldata) {
				if (schooldata.code == 0) {
					var str = "<option value='00'>请选择学校</option>";
					for(var i = 0; i < schooldata.count; i++){
						str += '<option value=' + schooldata.data[i].schoolid + '>'+ schooldata.data[i].schoolName +'</option>';
					}
					$("#selschool").append(str);
					form.render("select");
				}
				else{
					layer.msg('暂无对应的学校', {icon: 2});
					$("#selschool").html("");
					form.render("select");
				}
				
			}
		});
	});
	
	/*加载已发轶事表格*/
	table.render({
		elem: '#issendane',
		url: '../sysanecdotemanagement/getallanecdote',
		title: '轶事信息数据表',
		height:"full-125",
		skin: 'line',
		even: true,
		cols: [
			[{
				type: 'numbers',
				title: '序号',
				width: '10%'
			}, {
				field: 'topic',
				title: '轶事标题',	
				align: "center",
				width: '20%'
			}, {
				field: 'involveStudent',
				title: '当事人',
				align: "center",
				width: '11%'
			}, {
				field: 'sendRealName',
				title: '发送人',
				align: "center",
				width: '10%'
			},{
				field: 'receiveRealName',
				title: '接收人姓名',
				align: "center",
				width: '10%'
			}, {
				field: 'handlerStatus',
				title: '处理状态',
				templet : '#powerbar',
				align: "center",
				width: '10%'
			}, {field: 'anlev',width: '9%', title: '紧急程度',align:'center',templet:'#anecdoteTypeText'}
			,{
				field: 'sendTime',
				title: '发送时间',
				sort: true,
				align: "center",
				width: '10%'							
			},{
				title: '操作',
				toolbar: '#barDemo',
				align: "center",
				width:'10%'
			}]
		],
		page: {
			layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
			groups: 5,
			limit: 10,
			limits: [10, 20, 30, 40, 50],
			theme: '#1E9FFF',						
		}
	});

	/*点击查询对轶事进行筛选*/
	$("#btnselanecdote").click(function(){
		var schoolid=$("#selschool").val();
		var topic=$("#topic").val();
		if(schoolid==00 || schoolid=='null' || schoolid==null){
			schoolid="";
		}
		table.render({
			elem: '#issendane',
			url: '../sysanecdotemanagement/getallanecdote?schoolid='+schoolid+'&topic='+topic,
			title: '轶事信息数据表',
			height:"full-120",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					width: '10%'
				}, {
					field: 'topic',
					title: '轶事标题',	
					align: "center",
					width: '20%'
				}, {
					field: 'involveStudent',
					title: '当事人',
					align: "center",
					width: '16%'
				}, {
					field: 'sendRealName',
					title: '发送人',
					align: "center",
					width: '10%'
				},{
					field: 'receiveRealName',
					title: '接收人姓名',
					align: "center",
					width: '10%'
				}, {
					field: 'handlerStatus',
					title: '处理状态',
					templet : '#powerbar',
					align: "center",
					width: '10%'
				}, {
					field: 'sendTime',
					title: '发送时间',
					sort: true,
					align: "center",
					width: '14%'							
				},{
					title: '操作',
					toolbar: '#barDemo',
					align: "center",
					width:'10%'
				}]
			],
			page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',						
			}
		});
	});

	
	//查看已发轶事详情
    table.on('tool(anecdote)', function(obj){
	    var data = obj.data;
	    $("#anecdotetitle").text(data.topic);
		$("#sendname").text(data.sendRealName);
		$("#sendtime").text(data.sendTime);
		$("#anecdoteCon").html(data.acontent);
		
		$("#pcauses").html(data.causes);
		$("#pperformance").html(data.performance);
		$("#pdealedwith").html(data.dealedwith);
		$("#ptreatmenteffect").html(data.treatmenteffect);
		
		var reviewRealName = data.reviewRealName;
		var reviewTime = data.reviewTime;
		var reviewContent = data.reviewContent;
		if(reviewRealName == "" || reviewTime == "" || reviewContent == ""){
			$("#reviewContent").text("暂时还没人回复！");
		}else{
			$("#reviewRealName").text(reviewRealName);
			$("#reviewTime").text(reviewTime);
			$("#reviewContent").text(reviewContent);
		}
		
		var reviewStatus = data.reviewStatus;
		if(reviewStatus == 1001){
			$("#reviewStatus").text("同意");
		}else if(reviewStatus == 1002){
			$("#reviewStatus").text("不同意");
		}else if(reviewStatus == 1003){
			$("#reviewStatus").text("已阅");
		}
	    if(obj.event === 'view'){
	    	var index = layer.open({
		        type: 1, 
		        title: '已发轶事详情',
		        area: ['850px', '550px'],
		        shade: 0.8,
		        content: $('#selissendane'),
		        maxmin: true,
		        cancel: function(){ 
				   $(".selissendane-con").css("display","none");
				}
		    });
	    	layer.full(index);
	    }
	 });
});